﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Windows.Forms.DataVisualization.Charting;

namespace 玩具商城管理系统.start
{
    public partial class score : Form
    {
        public score()
        {
            InitializeComponent();
        }
        SqlDataAdapter daEmployee, daProform;
        DataSet ds = new DataSet();
        void init()
        {
            string str = "select employee_name 员工姓名,count(o.orderT_id) 订单数,sum(profit) 总利润\r\nfrom employee e, orderT o\r\nwhere e.employee_name=o.employee_id and orderT_check='已审核'\r\ngroup by e.employee_name";
            string sdr = "select employee_id as 员工编号,employee_name as 员工姓名,employee_ipone as 员工电话,employee_birth as 员工生日 ,employee_sex as 员工性别 ,employee_money as 员工工资 ,employee_home as 员工住址 ,employee_day as 员工生日 ,employee_introduct as 员工描述 from employee where depart_id=5";
            daProform = new SqlDataAdapter(str, DB.cn);
            daEmployee = new SqlDataAdapter(sdr,DB.cn);
            daEmployee.Fill(ds, "employee_info");
            daProform.Fill(ds, "Proform_info");
        }
        void showAll()
        {
            DataView dvProform =new DataView(ds.Tables["Proform_info"]);
            dgvproform.DataSource = dvProform;
            DataView dvEmployee = new DataView(ds.Tables["employee_info"]);
            dgvemployee.DataSource = dvEmployee;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void chart1_Click(object sender, EventArgs e)
        {

        }
       
        private void score_Load(object sender, EventArgs e)
        {
            init();
            showAll();
            string[] Xname =new string[ds.Tables["Proform_info"].Rows.Count];
            double[] Yprofit = new double[ds.Tables["Proform_info"].Rows.Count];
            for(int i = 0; i < ds.Tables["Proform_info"].Rows.Count; i++)
            {
                Xname[i] = ds.Tables["Proform_info"].Rows[i][0].ToString();
                Yprofit[i] = double.Parse(ds.Tables["Proform_info"].Rows[i][2].ToString());
            }
            DisplayChat(Xname,Yprofit,"员工业绩图");
        }
        void DisplayChat(string[] xlabels, double[] yvalues ,string serName)
        {
            chart1.Series.Clear();
            Series col = new Series(serName);
            for(int i = 0;i < xlabels.Length;i++)
            {
                DataPoint dp =new DataPoint(i, yvalues[i]);
                dp.AxisLabel = xlabels[i];
                col.Points.Add(dp);
            }
            chart1.Series.Add(col);
            chart1.ChartAreas[0].AxisX.Interval = 1;
            chart1.Invalidate();
        }
    }
}
